<template>
  <div id="app">
    <!-- 顶部Header区域 -->
    <mt-header fixed title="千百汇商城">
			<span  slot="left" @click="back" v-show="f">
    		<mt-button icon="back">返回</mt-button>
  		</span>
		</mt-header>
    <!-- 中间路由区域 -->
		<transition>
			<router-view></router-view>
		</transition>
    <!-- 底部Tabbar区域 -->
    <nav class="mui-bar mui-bar-tab">
			<div class="mui-tab-item" @click="toPage('/home')">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</div>
			<div class="mui-tab-item" @click="toPage('/member')">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">会员</span>
			</div>
			<div class="mui-tab-item"  @click="toPage('/shopcar')">
				<span class="mui-icon mui-icon-extra mui-icon-extra-cart">
					<span class="mui-badge" id="badge">{{this.$store.getters.getallcount}}</span>
				</span>
				<span class="mui-tab-label" >购物车</span>
			</div>
			<div class="mui-tab-item" @click="toPage('/search')">
				<span class="mui-icon mui-icon-search"></span>
				<span class="mui-tab-label">搜索</span>
			</div>
		</nav>
  </div>
</template>
<script>

export default {
  data(){
    return {
			//控制是否显示返回图标的标识
			f:false
		}
  },
	//解决不在首页时刷新返回图标消失问题
	created(){
		this.f=this.$route.path==='/home'?false:true;
	},
  methods: {
		//返回上一页面
		back(){
			this.$router.go(-1)
		},
		toPage(path) {
			this.$router.push(path)
		}
	},
	watch:{
		//监听路由变化，路由为首页的路由时，返回图标隐藏
		'$route.path':function(newval){
			if('/home'===newval){
				this.f=false
			}else{
				this.f=true
			}
		}
	}
  
}

</script>

<style lang="less">

#app{
	//去除顶部Header不占位造成的影响
  padding-top:40px;
	padding-bottom: 50px;
	overflow-x:hidden;
	touch-action: none;
}
//为中间路由区域添加过渡动画效果
.v-enter{
	opacity: 0;
	transform: translateX(100%);
}
.v-leave-to{
	opacity: 0;
	transform: translateX(-100%);
	position: absolute;
}
.v-enter-active,
.v-leave-active{
	transition: all 0.5s ease;
}

</style>
